import 'package:flutter/material.dart';
import 'package:transparent_image/transparent_image.dart';
import 'package:ivc/routers/application.dart';
import "package:ivc/controller/controller.dart";
import "package:ivc/globals.dart" as globals;

class IIoTPortal extends StatefulWidget {
  @override
  IIoTPortalState createState() => new IIoTPortalState();
}

class IIoTPortalState extends State<IIoTPortal> {
  List<Map<String, String>> _opCardDataList = new List();
  bool _color;
  @override
  void initState() {
    super.initState();
    _color = false;

    var tmp = SuggestionController(null, null).getSuggestion("iiot");

    print("======");
    for (var kk in tmp) {
      print(kk);
      _opCardDataList.add(IIoTSuggestions.getCard(kk));
    }
    print(_opCardDataList.length);

    print("======");
    // tmp.map((f) => IIoTSuggestions().getCard(f));
  }

  @override
  Widget build(BuildContext context) {
    //super.build(context);
    return Scaffold(
        body: CustomScrollView(
      shrinkWrap: true,
      slivers: <Widget>[
        SliverAppBar(
            leading: FadeInImage.assetNetwork(
            placeholder: "assets/images/house.png",
            image: 'https://picsum.photos/250?image=9',
          ),

          flexibleSpace: FlexibleSpaceBar(
              //可以展开区域，通常是一个FlexibleSpaceBar
              centerTitle: true,
              title: Text("接入工业物联网的世界"),
              background: Image.network(
                "https://iiot.jp/wp-content/uploads/2019/01/dc4775226e5370fa43eeef2d0b421186.jpg",
                fit: BoxFit.cover,
              )),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.shopping_cart),
              tooltip: 'Open shopping cart',
              onPressed: () {
                Application.router.navigateTo(context, "/placeorder");
              },
            ),
          ],
          primary: true, //是否预留高度
          forceElevated: true,
          automaticallyImplyLeading: true,
          snap: false, //与floating结合使用
          expandedHeight: 100.0, //展开高度
          floating: false, //是否随着滑动隐藏标题
          pinned: true, //是否固定在顶部
          backgroundColor: Colors.lightGreen,
        ),
        /*SliverPadding(
          padding: const EdgeInsets.all(20.0),
          sliver: SliverList(
            delegate: SliverChildListDelegate(
              <Widget>[
                const Text('I\'m dedicating every dddday to you!!!!'),
                const Text('Domestic life was never quite my style'),
                const Text('When you smile, you knock me out, I fall apart'),
                const Text('And I thought I was so smart'),
              ],
            ),
          ),
        ),*/
        SliverToBoxAdapter(
            child: Row(
          children: <Widget>[
            Image.asset("assets/images/rcrobot.gif", height: 20),
            Text("小树根据您所在行业, 给您以下物联建议",
                style: new TextStyle(
                  color: Colors.black54,
                  fontSize: 12.0,
                )),
          ],
        )),
        SliverPadding(
          padding: const EdgeInsets.all(0.0),
          sliver: SliverList(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return Card(
                    color: Colors.deepOrangeAccent,
                    child: ListTile(
                  title: Text(_opCardDataList[index]["title"]),
                  subtitle: Text(_opCardDataList[index]["subtitle"]),
                  onTap: () {
                    globals.opCardData = _opCardDataList[index];
                    Application.router
                        .navigateTo(context, _opCardDataList[index]["route"]);
                  }
                ));
              },
              childCount: _opCardDataList.length,
            ),
          ),
        ),
        SliverToBoxAdapter(
            child: Container(
          width: 100,
          height: 300,
        )),
      ],
    ));
  }

  void testPress(BuildContext context, int index) {
    final snackBar = SnackBar(
      content: Text('Yay! A SnackBar! $index'),
      action: SnackBarAction(
        label: 'Undo',
        onPressed: () {
          // Some code to undo the change.
        },
      ),
    );

    // Find the Scaffold in the widget tree and use
    // it to show a SnackBar.
    Scaffold.of(context).showSnackBar(snackBar);
  }
}
